package com.xique.door.bean.validation;

import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.bean.request.device.DeviceAddRequest;
import com.xique.door.bean.request.device.DeviceEditRequest;
import org.springframework.stereotype.Component;

/**
 * @author shd
 * @create 2022/1/25 10:38
 */
@Component
public class DeviceValidation {

    public AjaxResult checkDeviceAddRequest(DeviceAddRequest request) {
        if ("gate".equals(request.getAccessType()) && StringUtils.isNull(request.getAreaId())) {
            return AjaxResult.error("所属区域不能为空");
        }
        if ("cell".equals(request.getAccessType()) && StringUtils.isNull(request.getBuildingId())) {
            return AjaxResult.error("所属楼栋不能为空");
        }
        if ("elevator".equals(request.getAccessType()) && StringUtils.isNull(request.getElevatorId())) {
            return AjaxResult.error("所属电梯不能为空");
        }
        return AjaxResult.success();
    }

    public AjaxResult checkDeviceEditRequest(DeviceEditRequest request) {
        if ("gate".equals(request.getAccessType()) && StringUtils.isNull(request.getAreaId())) {
            return AjaxResult.error("所属区域不能为空");
        }
        if ("cell".equals(request.getAccessType()) && StringUtils.isNull(request.getBuildingId())) {
            return AjaxResult.error("所属楼栋不能为空");
        }
        if ("elevator".equals(request.getAccessType()) && StringUtils.isNull(request.getElevatorId())) {
            return AjaxResult.error("所属电梯不能为空");
        }
        return AjaxResult.success();
    }
}
